package collection;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author DBX
 * @effect
 * @date 2021/09/04/19:43
 */
public class Test6 {
    private ServerSocket serverSocket;
    private Socket socket;

    public Test6() {
        try {
            System.out.println("服务启动中");
            serverSocket = new ServerSocket(8088);
            System.out.println("服务启动成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    InputStream is;
    public void start(){
        try {
            System.out.println("等待连接");
            socket = serverSocket.accept();
            System.out.println("连接成功");
            is= socket.getInputStream();
            int b;
            while ((b = is.read())!=-1){
                System.out.print((char)b);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public static void main(String[] args) {
        Test6 t = new Test6();
        t.start();
    }
}
